package com.laoxu.java.ms.service;

import com.laoxu.java.ms.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author laoxu
 * @Date 2022/12/16 14:24
 * @Desc 模拟用户数据
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService{
    private List<User> users = new ArrayList<>();

    @PostConstruct
    private void initUserData(){
        log.info("初始化用户数据...");
        users.add(new User(1,"zhangsan","zhangsan@123.com"));
        users.add(new User(2,"lisi","lisi@123.com"));
        users.add(new User(3,"laoxu","laoxu@123.com"));
    }

    @Override
    public List<User> getUsers() {
        return users;
    }

    @Override
    public User getUserById(Integer id) {
        for (int i = 0; i < users.size(); i++) {
            if(users.get(i).getId()==id){
                return users.get(i);
            }
        }

        return null;
    }
}
